import vue from 'vue';

import toastComponent from './Toast.vue';

const ToastConstructor = vue.extend(toastComponent);

function showToast(text,duration=2000) {
    const toastDom = new ToastConstructor({
        el:document.createElement('div'),
        data(){
            return {
                text:text,
                showContent:true,
                showWrap:true,
            }
        }
    });
    document.body.appendChild(toastDom.$el);

    // setTimeout(function () {
    //     toastDom.showContent=false;
    // },duration-1250);
    // setTimeout(function () {
    //     toastDom.showWrap=false;
    // },duration);
    setTimeout(()=>{toastDom.showContent=false},duration-1250);
    setTimeout(()=>{toastDom.showWrap=false},duration);



}
function registryToast() {
    vue.prototype.$toast = showToast;
}
export default registryToast;
